package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type byteCount struct {
	intCount, enCount, spaceCount, hanCount, otherCount int
}

func main() {
	var count byteCount
	fmt.Println(count)
	fileName := "/Users/jumao/go/src/go_code/go_learning/chapter12_document_function/123.txt"
	file, err := os.Open(fileName)
	if err != nil {
		fmt.Printf("open file err=%v", file)
	}
	defer file.Close()
	reader := bufio.NewReader(file)
	for {
		str, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		for _, v := range str {
			switch {
			case v >= 'a' && v <= 'z':
				fallthrough
			case v >= 'A' && v <= 'Z':
				count.enCount++
			case v >= '0' && v <= '9':
				count.intCount++
			case v == ' ':
				count.spaceCount++
			case v >= '一' && v <= 40869:
				count.hanCount++
			default:
				count.otherCount++
			}
		}
		fmt.Printf("数字:%v,字母:%v,空格:%v,汉字:%v,其他%v\n", count.intCount, count.enCount, count.spaceCount, count.hanCount, count.otherCount)
	}
}
